package com.sunclouder.cactus.common.model;

import io.swagger.v3.oas.annotations.media.Schema;

import java.io.Serializable;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * 传参--分页参数
 */
public class PageMeta implements Serializable {
    @Schema(description = "页码", required = true, example = "1")
    private @NotNull @Min(value = 1L, message = "页码不能小于1") long pageNum;
    @Schema(description = "每页条数", required = true, example = "10")
    private @NotNull @Min(value = 1L, message = "每页条数不能小于1") @Max(value = 100L, message = "每页条数不能大于100") int pageSize;

    public long getOffset() {
        return (this.pageNum - 1L) * (long) this.pageSize;
    }

    public long getPageNum() {
        return this.pageNum;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public void setPageNum(final long pageNum) {
        this.pageNum = pageNum;
    }

    public void setPageSize(final int pageSize) {
        this.pageSize = pageSize;
    }

    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof PageMeta)) {
            return false;
        } else {
            PageMeta other = (PageMeta) o;
            if (!other.canEqual(this)) {
                return false;
            } else if (this.getPageNum() != other.getPageNum()) {
                return false;
            } else {
                return this.getPageSize() == other.getPageSize();
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof PageMeta;
    }

    public int hashCode() {
        int result = 1;
        long $pageNum = this.getPageNum();
        result = result * 59 + (int) ($pageNum >>> 32 ^ $pageNum);
        result = result * 59 + this.getPageSize();
        return result;
    }

    public String toString() {
        return "PageMeta(pageNum=" + this.getPageNum() + ", pageSize=" + this.getPageSize() + ")";
    }

    public PageMeta() {
    }

    public PageMeta(final long pageNum, final int pageSize) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }
}
